$(function () {
    let sdk = baidubce.sdk;
    // let sdk = require("@baiducloud/sdk");
    let VodClient = sdk.VodClient;
    let config = {
        endpoint: 'http://vod.bj.baidubce.com',
        credentials: {
            ak: 'd7b0528d41804aca885b7ad4cd189d78',
            sk: 'e63ec63116ee41ffbb0d11e652e14f18',
        },
    };
    const client = VodClient(config);
    // 上传视频

    let $upload_file_server = $("#upload-file-server");
    $upload_file_server.change(function () {
        alert("正在上传视频");
        let title = $("#news-title").val();
        if(!title){
            fAlert.alertErrorToast("请先填写课程标题之后，再上传视频！");
            $(this).val("");
            return;
        }
        let desc = $("#news-desc").val();
        if(!desc){
            $(this).val("");
            fAlert.alertErrorToast("请先填写课程描述之后，再上传视频！");
            return;
        }
        let video_file = this.files[0];
        console.log(video_file);
        let video_type = video_file.type;
        let blob = new Blob([video_file], {type: video_type});
        // video_file = {lastModified: 123433124535422, lastModifiedDate: "", name: "adv.mp4", size: 123212, type: "video/mp4"}
        console.log(video_file);

        client.createMediaResource(title, desc, blob)

            .then(function (response) {
                console.log(response);
            })
            .catch(function (error) {
                fAlert.alertErrorToast(error);
            });
    });
});